﻿using System;
using System.Collections.Generic;
using WeiboWPSdk.Api;

namespace WeiboWPSdk {
    /// <summary>
    /// 客户端操作类
    /// </summary>
    public class WeiboClient {
        public WeiboClient(OAuth2 oauth) {
            OAuth = oauth;
            var httpHelper = new ClientHttpHelper(oauth);
            _apiDic[typeof(UserApi)] = new UserApi(httpHelper);
            _apiDic[typeof(StatusApi)] = new StatusApi(httpHelper);
            _apiDic[typeof(CommentApi)] = new CommentApi(httpHelper);
            _apiDic[typeof(AccountApi)] = new AccountApi(httpHelper);
            _apiDic[typeof(FriendshipApi)] = new FriendshipApi(httpHelper);
            _apiDic[typeof(RemindApi)] = new RemindApi(httpHelper);
            _apiDic[typeof(RegisterApi)] = new RegisterApi(httpHelper);
            _apiDic[typeof(CommonApi)] = new CommonApi(httpHelper);
            _apiDic[typeof(ShortUrlApi)] = new ShortUrlApi(httpHelper);
            _apiDic[typeof(SearchApi)] = new SearchApi(httpHelper);
            _apiDic[typeof(FavoriteApi)] = new FavoriteApi(httpHelper);
            _apiDic[typeof(TagApi)] = new TagApi(httpHelper);
        }

        private readonly IDictionary<Type, ApiBase> _apiDic = new Dictionary<Type, ApiBase>();

        /// <summary>
        /// 授权对象
        /// </summary>
        public OAuth2 OAuth { get; private set; }

        /// <summary>
        /// 获取接口实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T Api<T>() where T : ApiBase {
            return (T)_apiDic[typeof(T)];
        }
    }
}
